#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.61])
AC_INIT(libsigcomp, 0.1, diopmamadou@yahoo.fr)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/DeflateCompressor.cxx])
AC_CONFIG_HEADERS([config.h])
AC_PROG_RANLIB

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_AWK
AC_PROG_INSTALL
AC_PROG_CPP
AC_PROG_MKDIR_P

# Checks for libraries.

# Checks for header files.
AC_CHECK_HEADERS([limits.h malloc.h stddef.h stdint.h stdlib.h string.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([floor memmove memset pow strtol])


# Using WIN32 threads
AC_ARG_ENABLE(win32thread,
   [  --enable-win32thread          Enable win32 threading (alternative to pthread)],
   [WIN32THREAD="$enableval"],
   [WIN32THREAD="no"]
)


# Using pthread?
AC_ARG_WITH(pthread, [  --with-pthread=PREFIX	Specify location of pthread], [pthread="$withval"], [pthread=no])
if test "$pthread" != no; then
   if test "$pthread" != yes; then
      CFLAGS="$CFLAGS -I$pthread/include"
      LDFLAGS="$LDFLAGS -L$pthread/lib"
   fi
   AC_CHECK_HEADERS([pthread.h],,AC_MSG_ERROR([pthread.h header not found]))
   AC_CHECK_LIB([pthread], [pthread_mutex_init],,AC_MSG_ERROR([pthread library not found]))
   AC_CHECK_LIB([pthread], [pthread_mutex_destroy],,AC_MSG_ERROR([pthread library not found]))
   AC_CHECK_LIB([pthread], [pthread_mutex_lock],,AC_MSG_ERROR([pthread library not found]))
   AC_CHECK_LIB([pthread], [pthread_mutex_unlock],,AC_MSG_ERROR([pthread library not found]))
else
   if test "$WIN32THREAD" = "no"; then
      AC_CHECK_HEADERS([pthread.h],,AC_MSG_ERROR([pthread.h header not found]))
      AC_CHECK_LIB([pthread], [pthread_mutex_init],,AC_MSG_ERROR([pthread library not found]))
      AC_CHECK_LIB([pthread], [pthread_mutex_destroy],,AC_MSG_ERROR([pthread library not found]))
      AC_CHECK_LIB([pthread], [pthread_mutex_lock],,AC_MSG_ERROR([pthread library not found]))
      AC_CHECK_LIB([pthread], [pthread_mutex_unlock],,AC_MSG_ERROR([pthread library not found]))
   fi
fi

dnl enable win32 threading or pthread
if test "$WIN32THREAD" = "yes"; then
   CXXFLAGS="$CXXFLAGS -DWIN32"
   AC_DEFINE(USE_WIN32_THREADS, 1, [Enable win32 threading])
else
  AC_DEFINE(USE_PTHREAD_TRHREADS, 1, [pthread available on the computer])
fi

#keeping inline functions
#ACX_CHECK_CXX_FLAGS(-fkeep-inline-functions,keep-inline-functions,CXXFLAGS="$CXXFLAGS -fkeep-inline-functions")
CXXFLAGS="$CXXFLAGS -fkeep-inline-functions"

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
